package net.m510.autosurfer.core.utils;

import java.util.logging.Logger;

import net.m510.autosurfer.common.exception.InvalidDocumentException;

import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class DocumentCheckUtils {
	private static final Logger log = Logger.getLogger(DocumentCheckUtils.class.getName());
	
	public static void checkTitleContainsText(Document doc, String text) throws InvalidDocumentException {
		final String TAG="title";
		Elements titles = doc.getElementsByTag(TAG);
		if ( titles.isEmpty() ) throw new InvalidDocumentException("no "+TAG+" tag", doc);
		Element title = titles.first();
		log.fine("title="+title);
		if ( !title.text().contains(text)) throw new InvalidDocumentException(TAG+"に「"+text+"」の文字がありません",doc);
	}
}
